package final2107.day13.cglibProxy;

import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

public class TimeCglibAspect implements MethodInterceptor{
    private Object target;

    public TimeCglibAspect(Object target){
        this.target = target;
    }
    @Override
    public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
        //获取当前时间
        long t1 = System.currentTimeMillis();
        //放行业务方法
        Object returnVal = method.invoke(target,args);
        //获取当前时间，计算耗时
        long t2 = System.currentTimeMillis();
        System.out.println("耗时："+(t2-t1)+"毫秒");
        return returnVal;
    }
}
